package gminet.infra.dao;

public class ImageTrasnferObject extends TransferObject {

    private static final long serialVersionUID = 1343412559823827015L;
    private String realFileName;
    private String filePath;
    private String fileName;
    private String mimeType;
    private long length;
    private byte[] data;

    public ImageTrasnferObject() {
        super();
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    public boolean hasData() {
        return getData() != null && getData().length > 0;
    }

    public String getRealFileName() {
        return this.realFileName;
    }

    public void setRealFileName(String realFileName) {
        this.realFileName = realFileName;
        int extDot = realFileName.lastIndexOf('.');
        if (extDot > 0) {
            String extension = realFileName.substring(extDot + 1);
            if ("bmp".equals(extension)) {
                this.mimeType = "image/bmp";
            } else if ("jpg".equals(extension)) {
                this.mimeType = "image/jpeg";
            } else if ("gif".equals(extension)) {
                this.mimeType = "image/gif";
            } else if ("png".equals(extension)) {
                this.mimeType = "image/png";
            } else {
                this.mimeType = "image/unknown";
            }
        }
    }

    public String getRealFileExtension() {

        String fileExtension = "";
        int extDot = getRealFileName().lastIndexOf('.');
        if (extDot > 0) {
            fileExtension = getRealFileName().substring(extDot + 1);
        }
        return fileExtension;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
    
    public String getCompleteFileName() {
        return getFilePath() + getFileName();
    }

    public long getLength() {
        return length;
    }

    public void setLength(long length) {
        this.length = length;
    }

    public String getMimeType() {
        return mimeType;
    }

}
